package sorting;

public class ShellSort {

	static int[] array = new int[] { 5, 9, 4, 0, 14, 6, 14, 99, 3, 44, 17 };

	public static void main(String[] args) {

		sort(array);

		printArray(array);

	}

	private static void sort(int[] array2) {

		int[] gaps = { 1, 3, 5, 7, 15 };

		for (int i = gaps.length - 1; i >= 0; i--) {
			insertionSort(gaps[i]);
		}

	}

	private static void insertionSort(int gap) {

		for (int i = gap; i < array.length; i++) {
			
			int j = i;
			int x = array[j];
			while (j - gap >= 0 && x < array[j-gap]) {
				array[j] = array[j-gap];
				j -= gap;
			}
			array[j] = x;
			
		}

	}

	private static void printArray(int[] array2) {
		for (int a : array) {
			System.out.print(a + " ");
		}
	}

	private static void swap(int[] array, int i, int j) {
		int tmp = array[i];
		array[i] = array[j];
		array[j] = tmp;

	}
}
